package com.company.笔试.mutiTread;

import java.util.concurrent.CountDownLatch;

/**
 * @author ylr
 * @version 1.0.0
 * @ClassName Main.java
 * @Description TODO
 * @createTime 2021年10月25日 10:45:00
 */
public class Main {
    public static void main(String[] args) {
        Object o = new Object();
        CountDownLatch countDownLatch = new CountDownLatch(1);


        new Thread(() -> {
            countDownLatch.countDown();
            for (int i = 0; i < 100; i++) {
                synchronized (o) {
                    System.out.println("A");
                    o.notify();
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        }).start();

        new Thread(() -> {
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < 100; i++) {
                synchronized (o) {
                    System.out.println("B");
                    o.notify();
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        }).start();


    }

    Main(){

    }

}
